﻿/*
 * Created by SharpDevelop.
 * User: Intel
 * Date: 19.12.2013
 * Time: 10:12
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Region.Utils;

namespace Region.Forms
{
  /// <summary>
  /// Description of SelectFilter.
  /// </summary>
  public partial class SelectFilter : Form
  {
    DirItem.DirItemParam m_Params;
    Dictionary<String,Dictionary<String,Object>> m_Ex;
    Boolean m_init = false;
    
    void ShowList()
    {
      m_init = false;
      Dictionary<String,Boolean> ParamCheck = new Dictionary<string, bool>();
      
      foreach(var i in m_Params.getParams()) ParamCheck[i] = true;
      foreach(var i in m_Ex)
      {
        filterList.Items.Add(new ListItemValue((String)i.Value["Caption"],i.Key),ParamCheck.ContainsKey(i.Key));
      }
      m_init = true;
    }
    public SelectFilter(DirItem.DirItemParam Params,Object Ex)
    {
      m_Params = Params;
      m_Ex = Ex as Dictionary<String,Dictionary<String,Object>>;
      //
      // The InitializeComponent() call is required for Windows Forms designer support.
      //
      InitializeComponent();
      ShowList();
    }
    
    void FilterListItemCheck(object sender, ItemCheckEventArgs e)
    {
      if (!m_init) return;
      String item = (String)((ListItemValue)filterList.Items[e.Index]).Value;
      if (e.CurrentValue == CheckState.Unchecked && e.NewValue == CheckState.Checked)
        m_Params.addParams(item,m_Ex[item]);
      else if (e.CurrentValue == CheckState.Checked && e.NewValue == CheckState.Unchecked)
        m_Params.delParams(item);
    }
  }
}
